<form action="{:sysuri()}" data-table-id="TagsData" class="layui-form" data-auto="true" method="post"
      style="min-height: 750px">
    <!--<div class="layui-card-body padding-left-40">-->

    <!--    <label class="layui-form-item relative block">-->
    <!--        <span class="help-label"><b>政策绑定标签</b> </span>-->
    <!--        <input class="layui-input" name="title" placeholder="请输入进展标题" required value='{$vo.title|default=""}'>-->
    <!--    </label>-->
    <!--</div>-->

    <!--<div class="layui-card-body padding-left-40">-->

    <!--    <label class="layui-form-item relative block">-->
    <!--        <span class="help-label"><b>责任单位</b> </span>-->
    <!--        <input class="layui-input" name="fbdw" placeholder="请输入责任单位" required value='{$vo.fbdw|default=""}'>-->
    <!--    </label>-->
    <!--</div>-->


    <div class="layui-form-item layui-col-xs12">
        <span class="help-label"><b>企业标签</b></span>
        <span class="color-desc margin-left-5"></span>
        <div id="peipeiList" class="xm-select-demo"></div>
        <input type="hidden" name="tags" id="qybq" value="{$vo.tags|default=''}">
    </div>


    <div class="layui-form-item" style="min-height: 500px">
        <span class="help-label"><b>企业列表</b></span>
        <span class="color-desc margin-left-5">数量: <span id="enterpriseNum">0</span></span>
        <div id="enterpriseList" class="xm-select-demo" style="min-height: 400px"></div>
        <style>
            #enterpriseList > xm-select {
                min-height: 350px;
            }

            #enterpriseList > xm-select > .xm-body {
                top: 100% !important;
            }

            #enterpriseList > xm-select > .xm-label.single-row {
                position: absolute;
                top: 0;
                bottom: 0px;
                left: 0px;
                right: 30px;
                overflow: auto;
            }

            #enterpriseList > xm-select > .xm-body .scroll-body {
                background-color: #e6e6e6;
                max-height: 250px !important;
            }

            #enterpriseList > xm-select > .xm-body .xm-search {
                margin-bottom: 0px !important;

            }


            #enterpriseList > xm-select > .xm-label.single-row .scroll {
                overflow-y: unset;
            }


            #enterpriseList > xm-select > .xm-label .scroll .label-content {
                display: flex;
                flex-wrap: wrap;
            }
        </style>
        <input type="hidden" name="enterprises" id="enterprises" value="{$enterprises|default=''}">
    </div>


    <div class="hr-line-dashed"></div>
    <input name='policy_id' type='hidden' value='{$zc_id}'>
    <input name='id' type='hidden' value=" {$vo.id|default='' }">

    <div class="layui-form-item text-center">
        <button class="layui-btn" type='submit'>保存数据</button>
        <button class="layui-btn layui-btn-danger" data-close type='button' data-confirm="确定要取消修改吗？">取消编辑</button>
    </div>
</form>

<script>
    $(function () {
        getUserList();
        getEnterpriseList();
    });

    function getUserList() {
        layui.use('xmSelect', function () {
            $.ajax({
                type: 'get',
                url: "/data/msjx.msjxNew/getQybqList.html",
                data: "",
                dataType: "json",
                success: function (res) {
                    if (res.code) {
                        console.log(res);
                        var datas = [];
                        res.data.forEach(function (item) {
                            var uuid = "{$vo.tags|default=''}".split(',');
                            if (uuid.length && uuid.findIndex(it => it == item.id) != -1) {
                                datas.push({name: item.name, value: item.id, selected: true});

                            } else {
                                datas.push({name: item.name, value: item.id});
                            }
                        });
                        xmSelect.render({
                            el: '#peipeiList',
                            tips: '请选择企业标签',//选项提示文字
                            filterable: true,//搜索模式
                            data: datas,
                            on: function (data) {
                                var selectArr = data.arr;
                                var seachArr = [];
                                for (var j = 0; j < selectArr.length; j++) {
                                    seachArr.push(selectArr[j].value)
                                }
                                $("#qybq").val(seachArr.toString());
                                getEnterpriseList(seachArr.toString());
                            }
                        })

                    } else {
                        console.log(res.info);
                    }
                    getEnterpriseList();
                },
                error: function (err) {
                    console.log(err)
                }
            });
        });
    }

    function getEnterpriseList() {
        var tag = $("#qybq").val();
        if (tag == "") {
            return;
        }
        layui.use('xmSelect', function () {
            $.ajax({
                type: 'get',
                url: "/data/user.qiyebiaoqian/getEnterpriseList.html?tag=" + tag,
                data: "",
                dataType: "json",
                success: function (res) {
                    if (res.code) {
                        var datas = [];
                        res.data.forEach(function (item) {
                            datas.push({name: item.qymc, value: item.id, selected: true});
                        });
                        $("#enterpriseNum").text(res.data.length);
                        console.log('------------', datas);
                        xmSelect.render({
                            el: '#enterpriseList',
                            tips: '请选择企业',//选项提示文字
                            filterable: true,//搜索模式
                            data: datas,
                            on: function (data) {
                                var selectArr = data.arr;
                                var seachArr = [];
                                for (var j = 0; j < selectArr.length; j++) {
                                    seachArr.push(selectArr[j].value)
                                }
                                console.log(seachArr.toString(), '------777777');
                                $("#enterprises").val(seachArr.toString());
                                $("#enterpriseNum").text(seachArr.length);
                            }
                        })
                    } else {
                        console.log(res.info);
                    }
                },
                error: function (err) {
                    console.log(err)
                }
            });
        });
    }
</script>